
class Node:
    def __init__(self,iterate):
        self.date=iterate
        self.next=None
    def setNext(self,newNext):
        self.next=newNext
    def getNext(self):
        return self.next
    def setDate(self,newdate):
        self.date=newdate
    def getDate(self):
        return self.date
class UnorderedList:
    def __init__(self):
        self.head=None

    def add(self,item):
        temp=Node(item)
        temp.setNext(self.head)
        self.head=temp

    def reverseList(self):
        pre,cur=None,self.head;
        lt=[]
        while cur:
            cur.next,pre,cur=pre,cur,cur.next
            lt.append(str(pre.date))
        return lt



n=int(input())

ls=[]
for i in range(n):
    lt=list(map(int,input().split()))
    lt.pop(0)
    ls.append(lt)
for i in ls:
    u = UnorderedList()
    for j in i:
        u.add(j)
    print(' '.join(u.reverseList()))
